<?
	$params[sid] = $sid;
	$params[action] = "editPlans";
	$url = "$baseURL/$webDIR/?".encode_params($params);

	if($errorMsg) echo "<center>$errorMsg<center>";
	$errorMsg = "";
	$plans = list_reseller_plans($id,'array');



	if(is_array($plans)){
		echo "<form action='$url' method='POST'>";
		foreach($plans as $plan){

			switch($plan[has_domain]){
				case "true": $plan[has_domain_sel][1]='selected'; break;
				case "false": $plan[has_domain_sel][2]='selected'; break;
				case "inplan": $plan[has_domain_sel][3]='selected'; break;
				default: $plan[has_domain_sel][2]='selected'; break;
			}

			$plan[domain_profit] = $plan[domain_price]-$plan[domain_real_price];
			if($plan[domain_profit] <= 0) $plan[domain_profit]=0;

			if($plan[plan_price]=='') $plan[plan_yn2]='selected';
			else $plan[plan_yn1]='selected';
			$plan[plan_profit] = $plan[plan_price]-$plan[plan_real_price];
			if($plan[plan_profit] <= 0) $plan[plan_profit]=0;

			if(!$plan[setup_fee]) $plan[setup_fee]=0;
			if(!$plan[domain_price]) $plan[domain_price]=0;
			if(!$plan[plan_price]) $plan[plan_price]=0;

                        $ch = "";
                        if($plan[display_on_index]=='true') $ch='checked';

			$plan[description] = implode(",",array_slice(explode("|",$plan[description]),0,5));


			$list .="
			<TABLE border=0 class='bTable' cellspacing='0' width='750'>
				<tr>
					<!-- <td><input type='checkbox' name='settings[$plan[plan]][display_on_index]' value='true' $ch> Display on the index page?</td> -->
					<td>$plan[plan] details:</td>
					<td colspan='10'>$plan[description]</td>
				</tr>
				<tr>
					<th>Description</th>
					<th>Yearly prices</th>
					<th>Minimum price</th>
					<th>Maximum price</th>
					<th>Wholesale</th>
    					<th>Commission</th>
				</tr>
				<tr>
					<td>Setup fee</td>
					<td>$<input type='text' name='settings[$plan[plan]][setup_fee]' size='4' value='$plan[setup_fee]'>(one time fee)</td>
					<td>$0</td>
					<td>$plan[setup_fee_max]</td>
					<td>N/A</td>
					<td>\$ $plan[setup_fee]</td>
				</tr>
				<tr>
					<td>Domains price</td>
					<td>
					<!--	<select name='settings[$plan[plan]][has_domain]'>

							<option value='true'   ".$plan[has_domain_sel][1].">Yes</option>
							<option value='false'  ".$plan[has_domain_sel][2].">No</option>
							<option value='inplan' ".$plan[has_domain_sel][3].">In Plan</option>
						</select>-->
						\$ <input type='text' name='settings[$plan[plan]][domain_price]' size='4' value='$plan[domain_price]'></td>
					<td>\$ $plan[domain_min_price]</td>
					<td>\$ $plan[domain_max_price]</td>
					<td>\$ $plan[domain_real_price]</td>
					<td>\$ $plan[domain_profit]</td>
				</tr>
				<tr>
					<td>12 Months price</td>
					<td>\$ <input type='text' name='settings[$plan[plan]][plan_price]'size='4' value='$plan[plan_price]'></td>
					<td>\$ $plan[plan_min_price]</td>
					<td>\$ $plan[plan_max_price]</td>
					<td>\$ $plan[plan_real_price]</td>
					<td>\$ $plan[plan_profit]</td>
				</tr>

			</TABLE><br>";
		}
		echo $list;
		echo "<BR>
			<TABLE border=0 class='bTable' cellspacing='0'>
				<TR>
					<TD>
						<input type='button' value='Back' onClick='javascript:history.go(-1)'>
					</TD>
					<TD>
						<input type='submit' value='Save settings'>
					</TD>
				</TR>
			</TABLE>
		";
		echo "</form>";
	}else{
		echo "<BR>
			<TABLE border=0 class='bTable' cellspacing='0'>
				<TR>
					<TD>
						We are sorry but we cannot process your request at the moment.<br>
						No plans available in the system.<br>
						Plase contact the support.

					</TD>
				</TR>
			</TABLE>
		";
	}
?>

